package com.ustc.hewei.consumerweb.controller;


import com.ustc.hewei.commonmodule.dto.Result;
import com.ustc.hewei.commonmodule.service.IFollowService;
import com.ustc.hewei.consumerweb.utils.UserHolder;
import com.ustc.hewei.nettyrpc2_0.common.annotation.AutowireService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hewei
 * @since 2022-10-05
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Resource
    private IFollowService followService;

    public IFollowService getFollowService() {
        return followService;
    }

    public void setFollowService(IFollowService followService) {
        this.followService = followService;
    }

    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followedUserId, @PathVariable("isFollow") boolean isFollowed) {
        return followService.follow(followedUserId, isFollowed, UserHolder.getUser());
    }

    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followedUserId) {
        return followService.isFollow(followedUserId, UserHolder.getUser());
    }

    @GetMapping("/common/{id}")
    public Result commonFollow(@PathVariable("id") Long followedUserId) {
        return followService.commonFollow(followedUserId, UserHolder.getUser());
    }
}